package com.upstairstechnology.oi.determination;

import java.io.IOException;
import java.util.Set;

/**
 * Base class for determination strategies.
 * 
 * @author Jeff Jensen
 */
public abstract class AbstractDeterminationStrategy implements
        DeterminationStrategy {
    /**
     * {@inheritDoc}
     */
    public Set<OutstandingIntegration> determineOutstandingIntegrations(
            Set<IntegrationCheck> integrationCheckSet) throws IOException {
        Set<OutstandingIntegration> outstandingIntegrationsSet =
                OutstandingIntegrationFactory.makeEmptySet();

        for (IntegrationCheck check : integrationCheckSet) {
            if (check.hasBranchspec()) {
                Set<OutstandingIntegration> tempSet =
                        templateProcessBranchspec(check);

                outstandingIntegrationsSet.addAll(tempSet);
            }

            if (check.hasSourceAndTarget()) {
                Set<OutstandingIntegration> tempSet =
                        templateProcessSourceTarget(check);

                outstandingIntegrationsSet.addAll(tempSet);
            }
        }

        return outstandingIntegrationsSet;
    }

    /**
     * Process an integration check using a branchspec. Implementations that do
     * not support branchspecs should throw UnsupportedOperationException.
     * 
     * @param check
     *            The integration check to perform.
     * @return The set of determined outstanding integrations.
     * @throws IOException
     *             On command processing errors.
     */
    protected abstract Set<OutstandingIntegration> templateProcessBranchspec(
            IntegrationCheck check) throws IOException;

    /**
     * Process an integration check using a source and target path pair.
     * Implementations that do not support source target pair should throw
     * UnsupportedOperationException.
     * 
     * @param check
     *            The integration check to perform.
     * @return The set of determined outstanding integrations.
     * @throws IOException
     *             On command processing errors.
     */
    protected abstract Set<OutstandingIntegration> templateProcessSourceTarget(
            IntegrationCheck check) throws IOException;
}
